var myError = require("./responObj.error");

function ResponObj(type){
	type = type.toLowerCase();
	//TODO:加入压缩、加密功能，客户端将自动解压、解密
	var result;
	switch(type){
		case "error":
		var args = Array.prototype.slice.call(arguments);
		//弹出第一个参数type
		args.shift();
		result = {
			type:"error",
			toString:myError.apply(null,args).toString()
		};
		break;
		case "json":
		result = {
			type:"json",
			toString:JSON.stringify(arguments[1])
		};
		break;
		case "html":
		result = {
			type:"json",
			toString:arguments[1]
		};
		break;
		default:
		result = {
			type:type,
			toString:String(arguments[1])
		};
	};
	return result;
}
module.exports = ResponObj;